<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
  
        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="props.formOperate!=='view'?['add']:[]"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xBjcost.quick Search Fields') })"
        />
  
        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />
  
        <!-- 表单 -->
        <PopupForm v-if="baTable.form.operate" />
    </div>
  </template>
  
  <script setup lang="ts">
  import { ref, provide, onMounted, inject } from 'vue'
  import baTableClass from '/@/utils/baTable'
  import { xBjline } from '/@/api/controllerUrls'
  import { defaultOptButtons } from '/@/components/table'
  import { baTableApi } from '/@/api/common'
  import { useI18n } from 'vue-i18n'
  import PopupForm from './popupForm.vue' 
  import Table from '/@/components/table/index.vue'
  import TableHeader from '/@/components/table/header/index.vue'
  
  const { t } = useI18n()
  
  const props = defineProps({
    formOperate:String
  })


  const lineId = ref('')
  provide('lineId',lineId)
  const isApprove = inject('isApprove') as boolean

  const tableRef = ref()
  const optButtons = defaultOptButtons(["edit","delete"])
  //处理列表  表单接口拦截器不一致的问题
  let url = new baTableApi(xBjline)
  url.actionUrl.set('add','/admin/xBjcost/add')
  url.actionUrl.set('edit','/admin/xBjcost/edit')
  url.actionUrl.set('del','/admin/xBjcost/del')
  console.log('url',url)
  const baTable = new baTableClass(
    url,
    {
        pk: 'ID',
        column: [
            { type: 'selection', align: 'center', operator: false },
            // { label: t('xBjcost.ID'), prop: 'ID', align: 'center', operator: 'RANGE' },
            { label: t('xBjcost.ITEMCODE'), prop: 'CODENAME', align: 'center' },
            // { label: t('xBjcost.TXPLACE'), prop: 'TXPLACE', align: 'center' },
            // { label: t('xBjcost.LOADPLACE'), prop: 'LOADPLACE', align: 'center' },
            // { label: t('xBjcost.RETURNPLACE'), prop: 'RETURNPLACE', align: 'center' },
            { label: t('xBjcost.PRICETYPE'), prop: 'PRICETYPE', align: 'center' },
            { label: t('xBjcost.TRANSDAYS'), prop: 'TRANSDAYS', align: 'center', operator: 'RANGE' },
            { label: t('xBjcost.UNITPRICE'), prop: 'UNITPRICE', align: 'center', operator: 'RANGE' },
            { label: t('xBjcost.MONEYTYPE'), prop: 'MONEYTYPE', align: 'center' },
            { label: t('xBjcost.TAXRATE'), prop: 'TAXRATE', align: 'center', operator: 'RANGE' },
            { label: t('xBjcost.BJNO'), prop: 'BJNO', align: 'center' ,show:false},
            { label: t('xBjcost.LINEID'), prop: 'LINEID', align: 'center', operator: 'RANGE',show:false },
            { label: t('xBjcost.COSTTYPE'), prop: 'COSTTYPE', align: 'center' ,show:false},
            { label: t('xBjcost.DISPLACE'), prop: 'DISPLACE', align: 'center',show:false },
            { label: t('xBjcost.VENDOR'), prop: 'VENDOR', align: 'center',show:false },
            { label: t('xBjcost.NOTAXPRICE'), prop: 'NOTAXPRICE', align: 'center', operator: 'RANGE' },
            { label: t('xBjcost.NOTE'), prop: 'NOTE', align: 'center',show:false },
            { label: t('xBjcost.OP'), prop: 'OP', align: 'center',show:false },
            { label: t('xBjcost.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160,show:false },
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false,show:props.formOperate!=='view'&&!isApprove },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'ID', order: 'desc' },
    },
    {
        defaultItems: [],
    },{

    },{
      getIndex:(obj:any)=>{
        lineId.value = obj.res.data.id
      }
    }
    
  )
  
  provide('baTable', baTable)
  const bjno = inject('bjno')

  onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.table.filter!.gstype = '1'
    baTable.table.filter!.type = '1'
    baTable.table.filter!.bjno = bjno
    baTable.mount()
    if(props.formOperate!=='add'){
        baTable.getIndex()?.then(() => {
            baTable.initSort()
            baTable.dragSort()
        })
    }
  })
  </script>
  
  <script lang="ts">
  import { defineComponent } from 'vue'
  export default defineComponent({
    name: 'xBjcost',
  })
  </script>
  
  <style scoped lang="scss"></style>
  